package com.qijian.quality.controller;

import java.util.List;

import com.qijian.common.utils.DateUtils;
import com.qijian.common.utils.ObjectUtils;
import lombok.RequiredArgsConstructor;
import com.qijian.common.utils.mybatis.WhereEntityTool;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.qijian.common.annotation.Log;
import com.qijian.common.annotation.PlugAnn;
import com.qijian.common.annotation.PlugParam;
import com.qijian.common.core.controller.BaseController;
import com.qijian.common.core.domain.AjaxResult;
import com.qijian.common.core.domain.entity.FlowableApproval;
import com.qijian.common.core.domain.entity.FlowableBack;
import com.qijian.common.enums.ApprovalDescriptionEnum;
import com.qijian.common.enums.BusinessType;
import com.qijian.common.exception.ServiceException;
import com.qijian.common.utils.SecurityUtils;
import com.qijian.quality.domain.InspectionResultRecordDetailValue;
import com.qijian.quality.domain.query.InspectionResultRecordDetailValueQuery;
import com.qijian.quality.service.IInspectionResultRecordDetailValueService;
import com.qijian.common.utils.poi.ExcelUtil;
import com.qijian.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;
/**
 * 实际检测值Controller
 *
 * @author zhangcheng
 * @date 2025-03-31
 */
@Api(tags = "实际检测值")
@RestController
@RequiredArgsConstructor
@RequestMapping("/quality/quality")
public class InspectionResultRecordDetailValueController extends BaseController {

    private final IInspectionResultRecordDetailValueService inspectionResultRecordDetailValueService;

    /**
     * 查询实际检测值列表
     */
    @PreAuthorize("@ss.hasPermi('quality:quality:list')")
    @GetMapping("/list")
    public TableDataInfo list(InspectionResultRecordDetailValueQuery query, Page<InspectionResultRecordDetailValue> page) {
        initOrderItem(InspectionResultRecordDetailValue.class, page.orders());
        return getDataTable(inspectionResultRecordDetailValueService.page(page, WhereEntityTool.invoke(query)));
    }

    /**
     * 导出实际检测值列表
     */
    @PreAuthorize("@ss.hasPermi('quality:quality:export')")
    @Log(title = "实际检测值" , businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public void export(InspectionResultRecordDetailValueQuery query, HttpServletResponse response) {
        new ExcelUtil<>(InspectionResultRecordDetailValue. class).exportExcel(response,inspectionResultRecordDetailValueService.list( WhereEntityTool.invoke(query)), "实际检测值数据");
    }

    /**
     * 获取实际检测值详细信息
     */
    @PreAuthorize("@ss.hasAnyPermi('quality:quality:list,quality:quality:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(inspectionResultRecordDetailValueService.getById(id));
    }

    /**
     * 新增实际检测值
     */
    @PreAuthorize("@ss.hasPermi('quality:quality:add')")
    @Log(title = "实际检测值" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InspectionResultRecordDetailValue inspectionResultRecordDetailValue) {
        return toAjax(inspectionResultRecordDetailValueService.save(inspectionResultRecordDetailValue));
    }

    /**
     * 修改实际检测值
     */
    @PreAuthorize("@ss.hasPermi('quality:quality:edit')")
    @Log(title = "实际检测值" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InspectionResultRecordDetailValue inspectionResultRecordDetailValue) {
        approval(inspectionResultRecordDetailValueService.getById(inspectionResultRecordDetailValue.getId()));
        return toAjax(inspectionResultRecordDetailValueService.updateById(inspectionResultRecordDetailValue));
    }

    /**
     * 删除实际检测值
     */
    @PreAuthorize("@ss.hasPermi('quality:quality:remove')")
    @Log(title = "实际检测值" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids) {
        ids.forEach(id -> approval(inspectionResultRecordDetailValueService.getById(id)));
        return toAjax(inspectionResultRecordDetailValueService.removeByIds(ids));
    }
}
